package cn.edu.scau.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cn.edu.scau.entity.People;
import cn.edu.scau.service.PeopleService;

@Controller
@RequestMapping("/people")
public class PeopleTest {

	@Autowired
	private PeopleService<People> people;

	public PeopleService<People> getPeople() {
		return people;
	}

	public void setPeople(PeopleService<People> people) {
		this.people = people;
	}

	@RequestMapping("/jump")
	public String jump() {

		System.out.println("asijdflas");
		return "upload";
	};

	@RequestMapping(method = RequestMethod.POST, value = "/save")
	public String save(@RequestParam(name = "files", required = false) MultipartFile file, HttpServletRequest request) {

		String path = request.getSession().getServletContext().getRealPath("/Upload/Upload/Photo/");
		System.out.println(path);
		People people = new People();
		people.setBirthday("1");
		people.setBirthplace("2");
		people.setColumnId(3);
		people.setDepartment("宣传部");
		people.setEmail("com");
		people.setName("mingwei");
		people.setPhotoUrl("asdfasdf");
		people.setPosition("主席");
		people.setProfession("信息学院");
		people.setProfile("asdfasdf");
		people.setQq("adkjfsadf");
		people.setSpecialty("asdfasdf");
		this.getPeople().saveImage(file, request, "2013:05:02 05:20:19");
		this.getPeople().add(people);
		return "NewFile";
	};

	@RequestMapping("/delete")
	public String delete(@RequestParam(name = "id") Integer id) {

		People people = this.getPeople().getPeopleByID(167);
		people.setBirthday("2014-03-20");
		this.getPeople().update(people, 167);
		this.getPeople().delete(168);
		return "NewFile";
	};

	@RequestMapping("/update")
	public String update() {
		return "NewFile";
	};

	@ResponseBody
	@RequestMapping("/front")
	public List findByPage() {

		System.out.println(this.getPeople());
		return this.getPeople().getPeopleProperty(53, "策划部", true);
	};

	@ResponseBody
	@RequestMapping("/back")
	public List findByPageback() {

		System.out.println(this.getPeople().countTheEntityNum(2, 10,false));
		return this.getPeople().getPeopleProperty(53, "策划部", false);
	};

}
